package com.enqualcomm.kids.mvp.login.wx.model;

import android.app.Activity;

import com.android.volley.VolleyError;
import com.enqualcomm.kids.config.userdefault.AppDefault;
import com.enqualcomm.kids.mvp.NetworkModel;
import com.enqualcomm.kids.mvp.login.wx.presenter.OnWXLoginListener;
import com.enqualcomm.kids.network.NetworkListener;
import com.enqualcomm.kids.network.SocketRequest;
import com.enqualcomm.kids.network.socket.request.LoginOtherParams;
import com.enqualcomm.kids.network.socket.response.LoginOtherResult;

import common.utils.MyLogger;

/**
 * Created by Administrator on 2016/9/8.
 */
public class WXLoginModelImpl extends NetworkModel implements WxLoginModel {

    AppDefault appDefault;

    public WXLoginModelImpl() {
        appDefault = new AppDefault();
    }

    @Override
    public void login(Activity activity, final OnWXLoginListener listener) {
        LoginOtherParams params = new LoginOtherParams(appDefault.getWXUserNickName(), appDefault.getWXUserid(), 1);
        loadDataFromServer(new SocketRequest<LoginOtherResult>(params, new NetworkListener<LoginOtherResult>() {
            @Override
            public void onError(VolleyError error) {
                error.printStackTrace();
                listener.loginError();
            }

            @Override
            public void onSuccess(LoginOtherResult response) {
                if (response.code == 0 && response.result != null) {
                    listener.loginSuccess(response);
                } else {
                    listener.loginError();
                }
            }
        }));
    }
}
